From ac54a29ffcfeefc33961680b5bdabaa53ff83ab9 Mon Sep 17 00:00:00 2001 From: oliskoli Date: Sat, 17 Jun 2006 21:31:54 +0000 Subject: [PATCH] Simplify code with strupper (or strlower). --- cet_util.c | 10 +--------- compegps.c | 9 ++------- garmin_txt.c | 10 ++-------- netstumbler.c | 6 ++---- pcx.c | 6 +----- tpo.c | 6 +----- 6 files changed, 9 insertions(+), 38 deletions(-) diff --git a/cet_util.c b/cet_util.c index d71f30248..a6b74d66b 100644 --- a/cet_util.c +++ b/cet_util.c @@ -866,7 +866,6 @@ int cet_validate_cs(const char *cs, cet_cs_vec_t **vec, char **cs_name) { char buff[128]; - char *c; cet_cs_vec_t *v; if ((cs == NULL) || (strlen(cs) == 0)) /* set default us-ascii */ @@ -879,14 +878,7 @@ cet_validate_cs(const char *cs, cet_cs_vec_t **vec, char **cs_name) v = cet_find_cs_by_name(cs); if (v != NULL) { - strncpy(buff, v->name, sizeof(buff)); - c = buff; - while (*c != '\0') - { - *c = toupper(*c); - c++; - } - *cs_name = xstrdup(buff); + *cs_name = strupper(xstrdup(v->name)); *vec = v; return 1; } diff --git a/compegps.c b/compegps.c index be4b2fa17..404230a66 100644 --- a/compegps.c +++ b/compegps.c @@ -1,6 +1,6 @@ /* - Support for CompeGPS waypoint (.wpt), route (.rte) and track (.trk) files, + Support for CompeGPS waypoint (.wpt), route (.rte) and track (.trk) files, Copyright (C) 2005 Olaf Klein, o.b.klein@t-online.de @@ -492,14 +492,9 @@ write_trkpt_cb(const waypoint *wpt) if (wpt->creation_time != 0) { - char *cx = buff; tm = *gmtime(&wpt->creation_time); strftime(buff, sizeof(buff), "%d-%b-%y %H:%M:%S", &tm); - while (*cx != '\0') - { - *cx = toupper(*cx); - cx++; - } + strupper(buff); } fprintf(fout, "T A %.10f%c%c %.10f%c%c ", diff --git a/garmin_txt.c b/garmin_txt.c index 7f0052d26..9709e85b2 100644 --- a/garmin_txt.c +++ b/garmin_txt.c @@ -954,10 +954,7 @@ parse_header(void) free_header(unknown_header); while ((str = csv_lineparse(NULL, "\t", "", column++))) { - header_lines[unknown_header][column] = xstrdup(str); - for (str = header_lines[unknown_header][column]; *str; str++) { - *str = toupper(*str); - } + header_lines[unknown_header][column] = strupper(xstrdup(str)); header_ct[unknown_header]++; if (header_ct[unknown_header] >= MAX_HEADER_FIELDS) break; } @@ -997,10 +994,7 @@ bind_fields(const header_type ht) fields = xmalloc(i + 2); strcpy(fields, headers[ht]); strcat(fields, "\t"); - for (c = fields; *c; c++) { - *c = toupper(*c); - } - c = fields; + c = strupper(fields); while ((c = strchr(c, '\t'))) *c++ = '\0'; for (i = 0; i < header_ct[unknown_header]; i++) { diff --git a/netstumbler.c b/netstumbler.c index c83424ab6..ded3c2c5b 100644 --- a/netstumbler.c +++ b/netstumbler.c @@ -274,7 +274,7 @@ fix_netstumbler_dupes(void) queue *elem, *tmp; extern queue waypt_head; const char *snptr; - char *tmp_sn, *tmp_ptr; + char *tmp_sn; unsigned long last_crc; char ssid[32 + 5 + 1]; @@ -285,9 +285,7 @@ fix_netstumbler_dupes(void) QUEUE_FOR_EACH(&waypt_head, elem, tmp) { bh->wpt = (waypoint *) elem; snptr = bh->wpt->shortname; - tmp_sn = xstrdup(snptr); - for (tmp_ptr = tmp_sn; *tmp_ptr; tmp_ptr++) - *tmp_ptr = tolower(*tmp_ptr); + tmp_sn = strlower(xstrdup(snptr)); bh->crc = get_crc32(tmp_sn, strlen(snptr)); xfree(tmp_sn); i ++; diff --git a/pcx.c b/pcx.c index 5600c06ce..72100e111 100644 --- a/pcx.c +++ b/pcx.c @@ -223,7 +223,6 @@ gpsutil_disp(const waypoint *wpt) double lon,lat; int icon_token = 0; char tbuf[1024]; - char *tp = tbuf; time_t tm = wpt->creation_time; lon = degrees2ddmm(wpt->longitude); @@ -232,10 +231,7 @@ gpsutil_disp(const waypoint *wpt) if (tm == 0) tm = current_time(); strftime(tbuf, sizeof(tbuf), "%d-%b-%y %I:%M:%S", localtime(&tm)); - while (*tp) { - *tp = toupper(*tp); - tp++; - } + strupper(tbuf); if (deficon) { icon_token = atoi(deficon); diff --git a/tpo.c b/tpo.c index a24f6da5c..d1df83e92 100644 --- a/tpo.c +++ b/tpo.c @@ -1476,12 +1476,8 @@ tpo_read(void) static void tpo_write_file_header() { - int i; - /* force upper-case state name */ - for (i=0; i<(int)strlen(output_state); i++) { - output_state[i] = toupper(output_state[i]); - } + strupper(output_state); if (strncmp("CA", output_state, 2) == 0) { -- 2.30.2